//---------------------------------------------------------------------------- Package
const _ = require('lodash');
//---------------------------------------------------------------------------- Config
const { MYSQL } = require('../../config');
//---------------------------------------------------------------------------- Plugin
const mysql = require('../../plugin/util/mysql');
const sheet = require('../../plugin/util/sheet');
//---------------------------------------------------------------------------- GET

exports.get = {

    //获取审核通过兼职列表
    "/part/time/list":async (ctx,next) => {
        let {job_name,mobile, address, address_detail, job_content, page,num, status} = ctx.query
        let where = 'where status = ' + status
        let sql = "select * from part_time "
        let arg = []
        if(job_name) where +=  " and job_name like '%" + job_name + "%'"
        if(mobile) where += " and mobile like '%" + mobile + "%'"
        if(address) where += " and address like '%" + address + "%'"
        if(address_detail) where += " and address_detail like '%" + address_detail + "%'"
        if(job_content) where += " and job_content like '%" + job_content + "%'"
        page = page < 1 ?  1 : page
        sql += where + ' order by time_start desc limit ?,?';
        arg.push((page - 1) * num)
        arg.push(parseInt(num))
        let info = await mysql.query(MYSQL.XIONGAN,[sql],arg)
        sheet[0].data = info[0]
        ctx.body = sheet[0]
        return 
    },

    //兼职详细信息
    "/part/time/detail":async (ctx,next) => {
        let {id} = ctx.query
        let sql = "select * from part_time where id = ?"
        let arg = [id]
        let info = await mysql.query(MYSQL.XIONGAN,[sql],arg)
        sheet[0].data = info[0]
        ctx.body = sheet[0]
        return 
    },
    
    //分情况获取条数
    '/get/part/time/count':async(ctx,next) =>{
        let sql = ''
        let status = ctx.query.status
        sql = 'select count(id) as countnum from part_time where status=' +  status
        let info = await mysql.query(MYSQL.XIONGAN,[sql],[])
        sheet[0].data = info[0]
        ctx.body = sheet[0]
        return 
      }
    
    
}

exports.post = {

}

exports.put = {

    //更新兼职信息
    "/update/part/time":async (ctx,next) => {
        let {id,status,remark} = ctx.request.fields
        await mysql.query(MYSQL.XIONGAN,['update part_time set remark = ? , status = ? where id = ? '],[remark,status,id])
        sheet[0].data = []
        ctx.body = sheet[0]
    }
}

exports.delete = {

}